//
//  PAReadagreementViewController.m
//  PAMobileWallet
//
//  Created by shen pu on 13-7-26.
//  Copyright (c) 2013年 平安付. All rights reserved.
//

#import "PAReadagreementViewController.h"
#import "PAReadagreementView.h"
#import "PANavView.h"

@interface PAReadagreementViewController ()

@end

@implementation PAReadagreementViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        readagreementView = [[PAReadagreementView alloc] initWithFrame:RECT_PHONE];
        readagreementView.parentController = self;
        readagreementView.backgroundColor = BGVIEW_COLOR;
        self.view = readagreementView;
        
        navView = [[PANavView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
        navView.delegate = self;
        [navView.gobackImage setTransform: CGAffineTransformMakeRotation(1.5*M_PI)];
        [navView setTitle:@"阅读条款"];
        [self.view addSubview:navView];
    }
    return self;
}

#pragma mark - PANavViewDelegate methods

- (void)sendSelf:(PANavView *)sendView
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeStateType"  object:@"dismiss"];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)sendShowType:(int)getShowType
{
    showType = getShowType;
}

- (void)viewDidAppear:(BOOL)animated
{
    [readagreementView.authScrollerView setContentOffset:CGPointMake(0, 0)];

    NSString * agreementText = [[NSBundle mainBundle] pathForResource:showType==1?@"PATransferAgreement":@"PAPayAgreement" ofType:@"txt"];
    NSString * agreementStr = [NSString stringWithContentsOfFile:agreementText encoding:NSUTF8StringEncoding error:nil];
    readagreementView.titleLable.text = agreementStr;
    CGSize constraint = CGSizeMake(300, 20000.0f);
    CGSize size = [agreementStr sizeWithFont:[UIFont fontWithName:@"Arial" size:14] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
    [readagreementView.titleLable setFrame:CGRectMake(10, 20, 300, size.height)];
    CGSize newSize = CGSizeMake(320,  size.height + 300);
    [readagreementView.authScrollerView setContentSize:newSize];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
